package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.vo.DeviceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description DeviceDataServiceImpl
 * @Author wangwei
 * @Date 2024-09-13
 */
@Service
public class DeviceDataServiceImpl implements DeviceDataService {
    @Autowired
    private DeviceDataMapper deviceDataMapper;

    /**
     * 获取物模型数据分页结果
     *
     * @param deviceDataPageReqDto
     * @return
     */
    @Override
    public PageResponse<DeviceDataVo> getDeviceDataPage(DeviceDataPageReqDto deviceDataPageReqDto) {
        //数据处理
        deviceDataPageReqDto.setStartDate(LocalDateTimeUtil.of(deviceDataPageReqDto.getStartTime()));
        deviceDataPageReqDto.setEndDate(LocalDateTimeUtil.of(deviceDataPageReqDto.getEndTime()));
        //1.开启分页
        PageHelper.startPage(deviceDataPageReqDto.getPageNum(),deviceDataPageReqDto.getPageSize());
        //2.获取page数据
        Page<DeviceDataVo> page = deviceDataMapper.selectDerviceData(deviceDataPageReqDto);
        //3.封装成pageResponse
        PageResponse<DeviceDataVo> response = new PageResponse<>(page);
        response.setRecords(page.getResult());
        return response;
    }
}
